//
//  HMLoginView.swift
//  webo
//
//  Created by apple on 2016/11/13.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit
import SnapKit

@objc protocol HMLoginViewDelegate: NSObjectProtocol  {
  
   func userWillLogin()
    //可选
 @objc optional func userWillReguster()
}

class HMLoginView: UIView {
  weak var delegate:HMLoginViewDelegate?
    
    
    func updateMessage(lblText: String,circleImgName: String,isHome: Bool = false){
        self.lblText.text = lblText
        self.circleView.image = UIImage(named: circleImgName)
        
        if isHome {
       startAnimation()
        }else{
            self.coverView.isHidden = true
            self.homeView.isHidden = true

        }
        
    }
    
  private  func startAnimation(){
        let animte = CABasicAnimation.init(keyPath: "transform.rotation")
        animte.toValue = M_PI*2
        animte.duration = 20
        animte.repeatCount = MAXFLOAT
        animte.isRemovedOnCompletion = false
        self.circleView.layer.add(animte, forKey: nil)
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor(white: 237/255, alpha: 1)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
  private  func setupUI(){


        self.addSubview(circleView)
        self.addSubview(coverView)
        self.addSubview(homeView)
        self.addSubview(lblText)
        self.addSubview(enterBtn)
        self.addSubview(registBtn)
        
        circleView.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.centerY.equalTo(self).offset(-80)
        }
        homeView.snp.makeConstraints { (make) in
        make.center.equalTo(circleView)
        }
        coverView.snp.makeConstraints { (make) in
            make.center.equalTo(circleView)
        }
       lblText.snp.makeConstraints { (make) in
//        make.leading.trailing.equalTo(circleView)
        make.centerX.equalTo(self)
        make.top.equalTo(circleView.snp.bottom).offset(20)
        }
        enterBtn.snp.makeConstraints { (make) in
            make.trailing.equalTo(self.snp.centerX).offset(-20)
            make.top.equalTo(lblText.snp.bottom).offset(40)
            make.width.equalTo(80)
        }
        registBtn.snp.makeConstraints { (make) in
            make.leading.equalTo(self.snp.centerX).offset(20)
            make.top.equalTo(lblText.snp.bottom).offset(40)
            make.width.equalTo(80)
        }
    
    self.enterBtn.addTarget(self, action: #selector(userLogin), for: .touchUpInside)
    self.registBtn.addTarget(self, action: #selector(userRegister), for: .touchUpInside)
    }

//    图片
  private  lazy var circleView: UIImageView = {
        let iv = UIImageView.init(image: #imageLiteral(resourceName: "visitordiscover_feed_image_smallicon"))
        return iv
    }()
  private  lazy var homeView: UIImageView = {
        let iv = UIImageView.init(image: #imageLiteral(resourceName: "visitordiscover_feed_image_house"))
        return iv
    }()
  private  lazy var coverView: UIImageView = {
        let iv = UIImageView.init(image: #imageLiteral(resourceName: "visitordiscover_feed_mask_smallicon"))
        return iv
    }()
//    文字
  private  lazy var lblText: UILabel = {
        let lb = UILabel(text: "关注一些人，回到这里看看有什么惊喜", fontSize: 14, numbLines: 0, tcolor: #colorLiteral(red: 0.501960814, green: 0.501960814, blue: 0.501960814, alpha: 1))
//        lb.text = "关注一些人，回到这里看看有什么惊喜"
//        lb.font.withSize(14)
//        lb.numberOfLines = 0
        lb.textAlignment = .center
        lb.preferredMaxLayoutWidth = 220
        return lb
    }()
    //    按钮button
    lazy var enterBtn: UIButton = {
        let btn = UIButton(title: "登入", fontSize: 14, color: #colorLiteral(red: 0.501960814, green: 0.501960814, blue: 0.501960814, alpha: 1), backimg: #imageLiteral(resourceName: "common_button_white"))
//        btn.setTitle("登入", for: .normal)
//        btn.setBackgroundImage(#imageLiteral(resourceName: "common_button_white"), for: .normal)
//        btn.setTitleColor(#colorLiteral(red: 0.501960814, green: 0.501960814, blue: 0.501960814, alpha: 1), for: .normal)
        return btn
    }()
    
    lazy var registBtn: UIButton = {
        let btn = UIButton(title: "注册", fontSize: 14, color: #colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1), backimg: #imageLiteral(resourceName: "common_button_white"))
//        btn.setTitle("注册", for: .normal)
//        btn.setTitleColor(#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1), for: .normal)
//        btn.setBackgroundImage(#imageLiteral(resourceName: "common_button_white"), for: .normal)
        return btn
    }()
    
    
   @objc private func userLogin(){
        self.delegate?.userWillLogin()
        print("asa")
    }
   @objc private func userRegister(){
        self.delegate?.userWillReguster?()
        print("asa")

    }
    
}
